package com.edu.controller.front.foodsymbol;

import com.edu.entity.Food;
import com.edu.service.food.FoodService;
import com.edu.service.food.FoodServiceImpl;
import com.edu.utils.ParamFormat;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author ZCN
 * @version 1.0
 * @date 2021/11/22 11:11
 */
/*
 *  前台推荐菜品\热门菜品\厨师推荐(获取数据拿到jsp中编译)
 */
@WebServlet("/front/index")
public class IndexServlet extends HttpServlet {
    private FoodService foodService = new FoodServiceImpl();
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        try {
            // 参数格式化
            ParamFormat.format(req, resp);
            // 今日推荐
            List<Food> todayRecommendFoods = foodService.todayRecommend();
            // 热门菜品
            List<Food> hotsFoods = foodService.hotsFoods();
            // 厨师推荐
            List<Food> cookRecommendFoods = foodService.cookRecommend();
            req.setAttribute("todayRecommendFoods",todayRecommendFoods);
            req.setAttribute("hotsFoods",hotsFoods);
            req.setAttribute("cookRecommendFoods",cookRecommendFoods);

            req.getRequestDispatcher("/front/index.jsp").forward(req,resp);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
